package messages;

import java.util.ArrayList;
import java.util.List;

public class MessageManager implements IMessageManager {
	
	private List<MessageAgent> m_agents;
	private MessageManager m_instance;
	private static Object m_mutex;
	
	// Constructor
	private MessageManager() {
		this.m_agents = new ArrayList<MessageAgent>();
	}

	@Override
	public IMessageManager getInstance() {
		if (this.m_instance == null){
			synchronized(m_mutex) {
				if (this.m_instance == null) {
					this.m_instance = new MessageManager();
				}
			}
		}
		return this.m_instance;
	}

	@Override
	public MessageAgent createAgent() {
		// create a new agent and add it to the agents
		MessageAgent result = new MessageAgent();
		m_agents.add(result);
		return result;
	}

}
